package com.javabi.htmlbuilder.html.element.form;

import com.javabi.htmlbuilder.html.HTMLBuilder;
import com.javabi.htmlbuilder.html.HTMLElementList;
import com.javabi.htmlbuilder.html.HTMLElementName;

/**
 * An HTML Input Element.
 */
public abstract class Input extends HTMLElementList<Input> {

	/** The name. */
	private String name = null;
	/** The value. */
	private Object value = null;

	/**
	 * Returns the type.
	 * @return the type.
	 */
	public abstract Type getType();

	/**
	 * Returns the name
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * Sets the name
	 * @param name the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * Returns the value
	 * @return the value
	 */
	public Object getValue() {
		return value;
	}

	/**
	 * Sets the value
	 * @param value the value to set
	 */
	public void setValue(Object value) {
		this.value = value;
	}

	@Override
	public HTMLBuilder appendAttributesTo(HTMLBuilder html) {
		html.attribute("type", getType().getType());
		if (name != null) {
			html.attribute("name", name);
		}
		if (value != null) {
			html.attribute("value", value);
		}
		return html;
	}

	/**
	 * Returns the element name.
	 * @return the element name.
	 */
	public final HTMLElementName getElementName() {
		return HTMLElementName.INPUT;
	}

	/**
	 * A Type
	 */
	public static enum Type {

		/** The text input type . */
		TEXT("text"),
		/** The text input type . */
		HIDDEN("hidden"),
		/** The text input type . */
		PASSWORD("password"),
		/** The text input type . */
		CHECKBOX("checkbox"),
		/** The text input type . */
		RADIO("checkbox"),
		/** The text input type . */
		SUBMIT("submit");

		/** The type. */
		private final String type;

		/**
		 * Creates a new type.
		 * @param type the type.
		 */
		private Type(String type) {
			this.type = type;
		}

		/**
		 * Returns the type.
		 * @return the type.
		 */
		public String getType() {
			return type;
		}
	}

}
